package com.yh.concert.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yh.concert.domain.dto.ConcertDto;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import com.yh.concert.mapper.YhOrderMapper;
import com.yh.concert.domain.YhOrder;
import com.yh.concert.service.IYhOrderService;

/**
 * 订单管理Service业务层处理
 *
 * @author yh
 * @date 2025-02-26
 */
@Service
public class YhOrderServiceImpl extends ServiceImpl<YhOrderMapper, YhOrder> implements IYhOrderService {

    @Autowired
    private YhOrderMapper yhOrderMapper;

    /**
     * 查询订单管理列表
     *
     * @param yhOrder 订单管理
     * @return 订单管理
     */
    @Override
    public List<YhOrder> selectYhOrderList(YhOrder yhOrder)
    {
        List<YhOrder> yhOrderList = yhOrderMapper.selectList(buildQueryWrapper(yhOrder));
        return yhOrderList;
    }

    @Override
    public int addOrder(ConcertDto concertDto) {

        YhOrder yhOrder = new YhOrder();
        yhOrder.setUserId(concertDto.getUserId());
        yhOrder.setMerchartId(concertDto.getMerchartId());
//        yhOrder.setSiteId(concertDto.getSiteId());
        yhOrder.setConcertId(concertDto.getId());
        yhOrder.setStatus(0L);

        return baseMapper.insert(yhOrder);
    }


    private LambdaQueryWrapper<YhOrder> buildQueryWrapper(YhOrder query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<YhOrder> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getUserId() != null, YhOrder::getUserId, query.getUserId());
        lqw.eq(query.getMerchartId() != null, YhOrder::getMerchartId, query.getMerchartId());
        lqw.eq(query.getSiteId() != null, YhOrder::getSiteId, query.getSiteId());
        lqw.eq(query.getConcertId() != null, YhOrder::getConcertId, query.getConcertId());
        lqw.eq(query.getStatus() != null, YhOrder::getStatus, query.getStatus());
        lqw.eq(query.getRemark() != null, YhOrder::getRemark, query.getRemark());
        lqw.orderByDesc(YhOrder::getCreateTime);
        return lqw;
    }

}
